using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using sdm.exam.domain;
using sdm.exam.domain.Abstract;
using sdm.exam.domain.DataContext;
using sdm.exam.domain.Entities;

namespace sdm.exam.test.Domain
{
    [TestClass]
    public class ExamDomainTest
    {
        private ExamDomain _domain = null;

        /// <summary>
        /// Initialize the test.
        /// </summary>
        [TestInitialize]
        public void Start()
        {
            Ninjector.Kernel.Bind<ISdmExamRepository>().ToConstant(new DataContext(ConnectionStrings.TestConnection));
            _domain = new ExamDomain();
        }

        /// <summary>
        /// Cleanup the test.
        /// </summary>
        [TestCleanup]
        public void End()
        {
            Ninjector.Kernel.Unbind<ISdmExamRepository>();
        }

        /// <summary>
        /// Test whether or not we are getting exams by a spefic education.
        /// </summary>
        [TestMethod]
        public void GetListByEducationTest()
        {
            //Ninjector.Kernel.Bind<ISdmExamRepository>().ToConstant(new DataContext(ConnectionStrings.TestConnection));

            //var domain = new ExamDomain();

            var education = new Education(){Id = 1,Name = "Test education"};
            var education1 = new Education(){Id = 2,Name = "Test education1"};

            var exam = new Exam { Education = education };
            var exam1 = new Exam { Education = education1 };

            _domain.AddExam(exam);
            _domain.AddExam(exam1);

            List<Exam> list = _domain.GetExamsListByEducation(education);

            foreach (Exam exams in list)
                Assert.AreEqual(education.Name, exams.Education.Name);
        }

        /// <summary>
        /// Test whether or not an exam is added.
        /// </summary>
        [TestMethod]
        public void AddExamTest()
        {
            //Ninjector.Kernel.Bind<ISdmExamRepository>().ToConstant(new DataContext(ConnectionStrings.TestConnection));

            //var domain = new ExamDomain();

            var exam = new Exam();

            int first = _domain.GetListOfExams().Count;

            _domain.AddExam(exam);

            int second = _domain.GetListOfExams().Count;

            Assert.AreEqual(second, first+1);
        }

        /// <summary>
        /// Test whether or not we get a list of all exams.
        /// </summary>
        [TestMethod]
        public void GetListOfExams()
        {
            //Ninjector.Kernel.Bind<ISdmExamRepository>().ToConstant(new DataContext(ConnectionStrings.TestConnection));
            //var domain = new ExamDomain();
            List<Exam> examList = null;

            examList = _domain.GetListOfExams();

            Assert.AreNotEqual(null,examList);
        }

        /// <summary>
        /// Test whether or not we get a list of exams from first semester.
        /// </summary>
        [TestMethod]
        public void ShowAllExamsForSemester()
        {
            //Ninjector.Kernel.Bind<ISdmExamRepository>().ToConstant(new DataContext(ConnectionStrings.TestConnection));
            //var domain = new ExamDomain();

            const int semester = 4;

            List<Exam> examsList = _domain.GetExamsListForSemester(semester);

            Assert.AreNotEqual(null, examsList);
        }
    }
}
